Latest update: April 2018
This tutorial introduces the GPIO function of FlashAir IoT Hub.
With the GPIO function, you can flicker an LED from FlashAir IoT Hub through FlashAir's GPIO and get the value of the switch.
The value of each pin of GPIO input set to "Trigger > GPIO input" on the screen is displayed as
High
or
Low
. The output set pin is displayed as
(Output)
.
However, with the initial setting of FlashAir, the GPIO function is disabled, and the value is not displayed. When using GPIO please enable GPIO function referring to CONFIG setting.
You can set the value to be output to each pin of GPIO with
High
or
Low
by the switch of "Action > GPIO output" on the screen.
After setting the value to be output with the switch, click the execution button to send the instruction to set the GPIO value to FlashAir.
The instruction to set the GPIO is registered as a job, and when FlashAir executes the job status changes from "Unexecuted" to "Executed".
Using the GPIO function of FlashAir IoT Hub, let's try flicking an LED (operate the LED blinking).
To use FlashAir's GPIO feature, this tutorial uses FlashAir prototyping board Airio RP.
For Airio RP, please refer to FlashAir prototyping board "Airio RP".
Using Airio RP and breadboard, connect as follows.
The Airio RP lights up when High is input to the LED terminal, and can be turned off by inputting Low, so connect D0 (0x02) to the LED terminal and control flicking at the output of D0.
The circuit diagram is created by Frizing in the schematic drawing software. By using Frizing's library published on Developer Resources, you can easily create circuit diagrams such as FlashAir and Airio RP, Please use it.
Set the input / output according to the Airio RP pin assignment. Edit the sample script
bootscript.lua
downloaded from FlashAir IoT Hub as follows and save it in the root directory of
FlashAir.
In this tutorial, only the processing related to GPIO is explained. Other processing will be explained in other tutorials.
local iothub = require("iothub")
iothub.startPioUpload(0x01)
-- iothub.stopPioUpload()
local cnt = 0
while(1) do
iothub.runJob()
iothub.addMeasurement({10, 20, cnt})
cnt = cnt + 1
sleep(10000)
collectgarbage("collect")
end
iothub.startPioUpload(ctrl)
.
1
for the bit corresponding to the pin you want to read and
0
for the bit corresponding to the pin you want to write.
0x01
.
iothub.stopPioUpload()
.
iothub.runJob()
, upload values of input GPIOs and download GPIO output instructions (jobs) issued
from FlashAir
IoT Hub.
Edit
/SD_WLAN/CONFIG
in FlashAir and add
IFMODE=1
in order to enable the GPIO function of FlashAir.
Pierce FlashAir into Airio RP, insert Micro USB cable connected to power supply and start up.
After start up, confirm that the LED of the Airio RP turns off, if it does, it's ready.
Now that we are ready, let's run it.
Set D0 (0x02) to
High
at the GPIO output of FlashAir IoT Hub and click the execute button.
You can confirm that the LED of the Airio RP lights up.
In this tutorial I did LED flicker using the LED of the Airio RP, but if you connect FlashAir you can remotely control your favorite device from the FlashAir IoT Hub. Please try whatever application you wish.